public class GetLongestPalindrome {
    public int getLongestPalindrome (String A) {
        // 最长回文子串
        // https://www.nowcoder.com/practice/b4525d1d84934cf280439aeecc36f4af?tpId=295&tqId=25269&sourceUrl=%2Fexam%2Foj%3Fpage%3D1%26tab%3DSQL%25E7%25AF%2587%26topicId%3D295
        // write code here
        int len = A.length();
        // dp[i][j]表示[i,j]之间的字符串是否是回文串
        boolean[][] dp = new boolean[len][len];
        int maxLength = 1;
        for (int i = 0; i < len; i++) {
            for (int j = 0; j <= i; j++) {
                if (A.charAt(i) == A.charAt(j) && (j+1 >= i-1 || dp[j+1][i-1])) {
                    dp[j][i] = true;
                    maxLength = Math.max(maxLength, i-j+1);
                }
            }
        }
        return maxLength;
    }

    public static void main(String[] args) {
        String A = "baabccc";
        GetLongestPalindrome obj = new GetLongestPalindrome();
        System.out.println(obj.getLongestPalindrome(A));
    }
}
